package dw.fastfile.common.util;


import com.alibaba.fastjson.JSONObject;
import com.jayway.jsonpath.JsonPath;
import dw.fastfile.business.dto.Dog;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @description:
 * @author: wanghao
 * @create: 2023-02-23 11:06
 **/
@Slf4j
public class JSONPathUtil {

    public static void main(String[] args) {
//        StringBuffer sql = new StringBuffer("1,2,3,");
//        String sql1 = sql.substring(0, sql.length() - 1);
//
//        System.out.println(sql1);
        Dog dog=new Dog() ;

        System.out.println(JSONObject.toJSON(dog));
    }

    public static void test1() {
        String s = "";
        JSONObject jsonObject = JSONObject.parseObject(s);
        System.out.println(jsonObject == null);
        System.out.println(jsonObject);
        jsonObject = new JSONObject();

        jsonObject.put("kpiId", "2");

        System.out.println(jsonObject.toJSONString());
    }

    public static void test() {
        String s = getS();

        String p1 = "$['oindiColumnData'][?(@.columncode==\"102\")].text";
        String c = null;

        List<LinkedHashMap> l1 = getValue(s, "$['oindiColumnData']");
        System.out.println(l1);
    }

    public static <T> T getValue(String json, String jsonPath) {
        try {
            return JsonPath.parse(json).read(jsonPath);
        } catch (Exception e) {
            return null;
        }
    }


    public static String getS() {
        return "{\n" +
                "\t\"name\": {\n" +
                "\t\t\"name\": \"1\",\n" +
                "\t\t\"pk\": \"1655558125647822856\"\n" +
                "\t},\n" +
                "\t\"type\": {\n" +
                "\t\t\"name\": \"客户类\",\n" +
                "\t\t\"pk\": \"ew7r3ha4pm000802\"\n" +
                "\t},\n" +
                "\t\"goal\": {\n" +
                "\t\t\"refpk\": \"\"\n" +
                "\t},\n" +
                "\t\"supportModel\": {\n" +
                "\t\t\"refname\": \"\",\n" +
                "\t\t\"refpk\": \"\"\n" +
                "\t},\n" +
                "\t\"standard\": \"1\",\n" +
                "\t\"id\": \"1655558125647822857\",\n" +
                "\t\"parentId\": \"ew7r3ha4pm000802\",\n" +
                "\t\"parentList\": \"客户类\",\n" +
                "\t\"ispublic\": false,\n" +
                "\t\"supportIndi\": \"\",\n" +
                "\t\"indisource\": 0,\n" +
                "\t\"indiprop\": 0,\n" +
                "\t\"oindiColumnData\": [{\n" +
                "\t\t\"id\": \"1655558125647822858\",\n" +
                "\t\t\"ts\": 1675932333000,\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\"columncode\": \"102\",\n" +
                "\t\t\"text\": \"1\",\n" +
                "\t\t\"ocolumn\": {\n" +
                "\t\t\t\"id\": \"ew7r3ha4pm000500\",\n" +
                "\t\t\t\"ts\": 1670917508000,\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\t\"columncode\": \"102\",\n" +
                "\t\t\t\"columnname\": \"达标标准\",\n" +
                "\t\t\t\"columndatatype\": 1,\n" +
                "\t\t\t\"iscalculable\": false,\n" +
                "\t\t\t\"isturn\": false,\n" +
                "\t\t\t\"bizprop\": 2,\n" +
                "\t\t\t\"datalen\": \"500\",\n" +
                "\t\t\t\"defaultshow\": 1\n" +
                "\t\t},\n" +
                "\t\t\"rules\": {\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"columncode\": \"102\",\n" +
                "\t\t\t\"ismodify\": true,\n" +
                "\t\t\t\"isvisible\": true,\n" +
                "\t\t\t\"isrequired\": true,\n" +
                "\t\t\t\"dispSeq\": 2\n" +
                "\t\t}\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"1655558125647822859\",\n" +
                "\t\t\"ts\": 1675932333000,\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\"columncode\": \"103\",\n" +
                "\t\t\"text\": \"1\",\n" +
                "\t\t\"ocolumn\": {\n" +
                "\t\t\t\"id\": \"ew7r3ha4pm000501\",\n" +
                "\t\t\t\"ts\": 1671264830000,\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\t\"columncode\": \"103\",\n" +
                "\t\t\t\"columnname\": \"卓越标准\",\n" +
                "\t\t\t\"columndatatype\": 1,\n" +
                "\t\t\t\"iscalculable\": false,\n" +
                "\t\t\t\"isturn\": false,\n" +
                "\t\t\t\"bizprop\": 2,\n" +
                "\t\t\t\"datalen\": \"500\",\n" +
                "\t\t\t\"defaultshow\": 1\n" +
                "\t\t},\n" +
                "\t\t\"rules\": {\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"columncode\": \"103\",\n" +
                "\t\t\t\"ismodify\": true,\n" +
                "\t\t\t\"isvisible\": true,\n" +
                "\t\t\t\"isrequired\": true,\n" +
                "\t\t\t\"dispSeq\": 3\n" +
                "\t\t}\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"1655558125647822860\",\n" +
                "\t\t\"ts\": 1675932333000,\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\"columncode\": \"122\",\n" +
                "\t\t\"text\": \"1\",\n" +
                "\t\t\"ocolumn\": {\n" +
                "\t\t\t\"id\": \"ew7r3ha4pm000519\",\n" +
                "\t\t\t\"ts\": 1675924912000,\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\t\"columncode\": \"122\",\n" +
                "\t\t\t\"columnname\": \"备注\",\n" +
                "\t\t\t\"columndatatype\": 1,\n" +
                "\t\t\t\"iscalculable\": false,\n" +
                "\t\t\t\"isturn\": true,\n" +
                "\t\t\t\"bizprop\": 2,\n" +
                "\t\t\t\"defaultshow\": 1\n" +
                "\t\t},\n" +
                "\t\t\"rules\": {\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"columncode\": \"122\",\n" +
                "\t\t\t\"ismodify\": true,\n" +
                "\t\t\t\"isvisible\": true,\n" +
                "\t\t\t\"isrequired\": true,\n" +
                "\t\t\t\"dispSeq\": 10\n" +
                "\t\t}\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"1655558125647822861\",\n" +
                "\t\t\"ts\": 1675932333000,\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\"columncode\": \"114\",\n" +
                "\t\t\"text\": \"质量\",\n" +
                "\t\t\"ocolumn\": {\n" +
                "\t\t\t\"id\": \"ew7r3ha4pm000511\",\n" +
                "\t\t\t\"ts\": 1670919160000,\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"tenantid\": \"ew7r3ha4\",\n" +
                "\t\t\t\"ytenantId\": \"ew7r3ha4\",\n" +
                "\t\t\t\"columncode\": \"114\",\n" +
                "\t\t\t\"columnname\": \"指标责任部门\",\n" +
                "\t\t\t\"columndatatype\": 1,\n" +
                "\t\t\t\"iscalculable\": false,\n" +
                "\t\t\t\"isturn\": false,\n" +
                "\t\t\t\"bizprop\": 2,\n" +
                "\t\t\t\"defaultshow\": 1\n" +
                "\t\t},\n" +
                "\t\t\"rules\": {\n" +
                "\t\t\t\"es\": 0,\n" +
                "\t\t\t\"columncode\": \"114\",\n" +
                "\t\t\t\"ismodify\": true,\n" +
                "\t\t\t\"isvisible\": true,\n" +
                "\t\t\t\"isrequired\": true,\n" +
                "\t\t\t\"dispSeq\": 11\n" +
                "\t\t}\n" +
                "\t}],\n" +
                "\t\"omainIndi\": {},\n" +
                "\t\"applyobject\": 1,\n" +
                "\t\"percent\": \"1.00\",\n" +
                "\t\"evalstandardRules\": {\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"columncode\": \"evalstandard\",\n" +
                "\t\t\"ismodify\": true,\n" +
                "\t\t\"isvisible\": true,\n" +
                "\t\t\"isrequired\": true,\n" +
                "\t\t\"dispSeq\": 0\n" +
                "\t},\n" +
                "\t\"indiWeightRules\": {\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"columncode\": \"indiWeight\",\n" +
                "\t\t\"ismodify\": true,\n" +
                "\t\t\"isvisible\": true,\n" +
                "\t\t\"isrequired\": true,\n" +
                "\t\t\"dispSeq\": 0\n" +
                "\t},\n" +
                "\t\"relatetargetRules\": {\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"columncode\": \"relatetarget\",\n" +
                "\t\t\"ismodify\": true,\n" +
                "\t\t\"isvisible\": true,\n" +
                "\t\t\"isrequired\": false,\n" +
                "\t\t\"dispSeq\": 0\n" +
                "\t},\n" +
                "\t\"supportRules\": {\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"columncode\": \"supportIndi\",\n" +
                "\t\t\"ismodify\": true,\n" +
                "\t\t\"isvisible\": false,\n" +
                "\t\t\"isrequired\": false,\n" +
                "\t\t\"dispSeq\": 0\n" +
                "\t},\n" +
                "\t\"indisourceRules\": {\n" +
                "\t\t\"es\": 0,\n" +
                "\t\t\"columncode\": \"indisource\",\n" +
                "\t\t\"ismodify\": false,\n" +
                "\t\t\"isvisible\": false,\n" +
                "\t\t\"isrequired\": false,\n" +
                "\t\t\"dispSeq\": 0\n" +
                "\t}\n" +
                "}";
    }

}
